package com.goodboys.base.controller;

import com.goodboys.base.resp.Response;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
import org.springframework.messaging.simp.SimpMessageType;

import java.util.Map;

/**
 * Created by CJ on 2018-05-19.
 */
public class BaseController<T>  {


    public static Response getRetunResult(Map result,Response response){
        Integer status = (Integer) result.get("status");
        return  (status == 1) ?  response.success(result.get("message")) :  response.failure((String)result.get("message"));
    }

    /**
     * 获取分页后的列表情况
     * @param result
     * @return
     */
    public static  Response getRetunPageList(Map result,Response response){
        Integer status = (Integer) result.get("status");
        if(status == 1){
            return response.success().packageData("total", result.get("total")).packageData("list", result.get("list"));
        }else {
            return response.failure((String) result.get("message"));
        }
    }

    public static MessageHeaders createHeaders(String sessionId) {
        SimpMessageHeaderAccessor headerAccessor = SimpMessageHeaderAccessor.create(SimpMessageType.MESSAGE);
        headerAccessor.setSessionId(sessionId);
        headerAccessor.setLeaveMutable(true);
        return headerAccessor.getMessageHeaders();
    }


}
